//============================================//
//  Doubly-Linked List Example
//  by Drake Bissett - 2013
//  --------------------------
//  Simple demo of a doubly-linked list:
//  -Each node contains a pointer to the previous
//  -node and to the next node in the series.
//  --------------------------
//  dsbissett@gmail.com
//  w32reverse@gmail.com
//============================================//
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
	struct node
	{
		int data;
		node* next;
		node* prev;
	};

	node* head;
	node* tail;
	node* n;
	node* temp;

	n = new node;
	n->data = 1;
	n->prev = NULL;
	head = n;
	tail = n;

	n = new node;
	n->data = 2;
	n->prev = tail;
	tail->next = n;
	tail = tail->next;

	n = new node;
	n->data = 3;
	n->prev = tail;
	tail->next = n;
	tail = tail->next;

	n = new node;
	n->data = 4;
	n->prev = tail;
	tail->next = n;
	tail = n;

	temp = head;

	cout << "Printing from Head to Tail:\n";
	while (temp != NULL)
	{
		cout << temp->data << " ";
		temp = temp->next;
	}
	cout << endl;

	temp = tail;

	cout << "Printing from Tail to Head:  ";
	while (temp != NULL)
	{
		cout << temp->data << " ";
		temp = temp->prev;
	}
	cout << endl;
	return 0;
}